package com.example.traning.mall.service.dict.impl;

import cn.hutool.core.bean.BeanUtil;
import com.example.traning.mall.controller.dict.vo.DictDistrictVO;
import com.example.traning.mall.dal.dataobject.dict.DictDistrict;
import com.example.traning.mall.dal.mysql.dict.DictDistrictMapper;
import com.example.traning.mall.service.dict.IDictDistrictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 省市区字典 服务实现类
 * </p>
 *
 * @author Lei Yu
 * @since 2025-04-29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DictDistrictServiceImpl implements IDictDistrictService {

    private final DictDistrictMapper dictDistrictMapper;

    @Override
    public List<DictDistrictVO> selectByParentId(String parentId) {
        List<DictDistrict> districts = dictDistrictMapper.selectByParentId(parentId);
        // 通过 BeanUtil 工具类 将 DO对象 转换成 VO 对象，也可以用 mapstruct
        // BeanUtil.copyProperties(); 复制对象
        // BeanUtil.copyToList(); 复制集合对象
        List<DictDistrictVO> vo = BeanUtil.copyToList(districts, DictDistrictVO.class);
        return vo;
    }
}
